home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / pc / BOBOLI.ZIP / SRC / MFONT.C < prev    next >
Encoding:
C/C++ Source or Header  |  1996-05-12  |  3.3 KB  |  159 lines

  1. #include <stdio.h>
  2. #include <dpmi.h>
  3. #include <sys\movedata.h>
  4. #include <stdlib.h>
  5. #include <sys\nearptr.h>
  6. #include "mgraph.h"
  7. #include "mfont.h"
  8. #include "mkey.h"
  9. #include <pc.h>
  10.  
  11. fontset font;
  12.   
  13. char scantoascii[86]=("!!1234567890-=!!qwertyuiop[]!~asdfghjkl:\"~~\\zxcvbnm,.?~*~ ~~~~~~~~~~~~~~!~-!~!+~!~~~~~");
  14.  
  15. void font_init(char *fname)
  16. {
  17.   FILE *f;
  18.   /* set the characters I couldn't figure out how to represent in the
  19.      initializer */
  20.   scantoascii[1]=27;
  21.   scantoascii[14]=8;
  22.   scantoascii[15]=9;
  23.   scantoascii[28]=13;
  24.   scantoascii[72]=24;
  25.   scantoascii[75]=8;
  26.   scantoascii[77]=26;
  27.   scantoascii[80]=25;
  28.   f=fopen(fname,"rb");
  29.   fread(font,1,sizeof(fontset),f);
  30.   fclose(f);
  31. }
  32.  
  33. char *input(char *text,int x,int y,byte len,byte col)
  34. {
  35.   char key;
  36.   int bx,j,count;
  37.   bx=x;
  38.   count=0;
  39.   text[0]='\0';
  40.   do {
  41.     while(!kbhit()) {
  42.       box(x,y,x+5,y+5,col,screen);
  43.       waitretrace();
  44.       box(x,y,x+5,y+5,0,screen);
  45.     }
  46.     key=getch();
  47.     if((key>='a')&&(key<='z')) key=key-32;
  48.     if((key==8)&&(count>0)) {
  49.       box(bx,y,x+5,y+5,0,screen);
  50.       text[--count]='\0';
  51.       print(bx,y,col,0,text,screen);
  52.       x=bx+strlen(text)*6;
  53.     }
  54.     if((key<126)&&(key>31)&&(count<len)) {
  55.       text[count++]=key;
  56.       text[count]='\0';
  57.       print(bx,y,col,0,text,screen);
  58.       x=bx+strlen(text)*6;
  59.     }
  60.   } while (key!=13);
  61.   return text;
  62. }
  63.  
  64. void printchar(unsigned char c,int x,int y,scrntype scrn,byte c1,byte c2)
  65. {
  66.   byte *src;
  67.   byte *dst;
  68.   register byte ty;
  69.   register byte tx;
  70.   c-=33;
  71.   if(c>63) return;
  72.   src=&(font[c][0]);
  73.   dst=&(scrn[x+y*320]);
  74.   for(ty=0;ty<5;ty++) {
  75.     tx=*(src++);
  76.     if(tx&1) {
  77.       *dst=c1;
  78.       *(++dst)=c2;
  79.     } else ++dst;
  80.     if(tx&2) {
  81.       *dst=c1;
  82.       *(++dst)=c2;
  83.     } else ++dst;
  84.     if(tx&4) {
  85.       *dst=c1;
  86.       *(++dst)=c2;
  87.     } else ++dst;
  88.     if(tx&8) {
  89.       *dst=c1;
  90.       *(++dst)=c2;
  91.     } else ++dst;
  92.     if(tx&16) {
  93.       *dst=c1;
  94.       *(++dst)=c2;
  95.     } else ++dst;
  96.     if(tx&32) {
  97.       *dst=c1;
  98.       *(++dst)=c2;
  99.     } else ++dst;
  100.     dst+=314;
  101.   }
  102. }
  103.  
  104. void print(int x,int y,byte c1,byte c2,char *s,scrntype scrn)
  105. {
  106.   int i;
  107.   for(i=0;i<strlen(s);i++) {
  108.     printchar(s[i],x,y,scrn,c1,c2);
  109.     x+=6;
  110.   }
  111. }
  112.  
  113. void printnum(int x,int y,byte c1,byte c2,long num,scrntype scrn)
  114. {
  115.   char text[40];
  116.   sprintf(text,"%i",num);
  117.   print(x,y,c1,c2,text,scrn);
  118. }
  119.  
  120. char *kb_input(char *text,int x,int y,byte len,byte col)
  121. {
  122.   char key;
  123.   int bx,j,count;
  124.   bx=x;
  125.   count=0;
  126.   text[0]='\0';
  127.   do {
  128.     while(!keypress()) {
  129.       box(x,y,x+5,y+5,col,screen);
  130.       waitretrace();
  131.       box(x,y,x+5,y+5,0,screen);
  132.     }
  133.     key=0;
  134.     for(j=1;j<85;j++)
  135.       if(keystate(j)==pressed) {
  136.         key=scantoascii[j];
  137.         j=84;
  138.       }
  139.     if((key>='a')&&(key<='z')) key=key-32;
  140.     if((keystate(LShift)==held)||(keystate(RShift)==held)) {
  141.       if((key>='a')&&(key<='z')) key=key-32;
  142.       if((key>='0')&&(key<='9')) key='!';
  143.     }
  144.     if((key==8)&&(count>0)) {
  145.       box(bx,y,x+5,y+5,0,screen);
  146.       text[--count]='\0';
  147.       print(bx,y,col,0,text,screen);
  148.       x=bx+strlen(text)*6;
  149.     }
  150.     if((key<126)&&(key>31)&&(count<len)) {
  151.       text[count++]=key;
  152.       text[count]='\0';
  153.       print(bx,y,col,0,text,screen);
  154.       x=bx+strlen(text)*6;
  155.     }
  156.   } while (key!=13);
  157.   return text;
  158. }
  159.